package cn.jhc.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import uuntil.Constants;
import cn.jhc.bean.UserSong;
import cn.jhc.db.UserDao;
import cn.jhc.db.UserSongDao;

/**
 * Servlet implementation class AddUserSongservlet
 */
@WebServlet("/usersong.do")
public class AddUserSongservlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddUserSongservlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		DataSource dataSource = (DataSource)request.getServletContext().getAttribute(Constants.H2_DATASOURCE);
		request. setCharacterEncoding("UTF-8");
		String songname=request.getParameter("songname");
		String songsinger=request.getParameter("songsinger");
		UserSong song=new UserSong(songname,songsinger);		
		UserSongDao.addUserSong(dataSource, song);
		response.sendRedirect("./listsong.do");
	}

}
